<?php
    $action_url='C=addons_modules&M=show_module_cp&module=spider&method=configFieldGroup';
   // $action_url .='&api='.$currentApi;
    $changeUrl=$action_url;
    $action_url .='&api='.$currentApi;
    $action_url .='&campaignId='.$currentcampaignId;
    $hidden=array('tableName'=>'spider_fields', 'api'=>$currentApi);

    $apiNames=$options->getApinames();
?>

<?php echo form_open($action_url, '',$hidden); ?>
<div class="formArea">
    <div>
        <div class="templateEditorTop">
            <h2>Configure Field Group</h2>
            <div class="search">
                <?php echo form_label("Select campaign", 'camapin_id');?>
                <select name="campaign_id" onchange="location = '<?php echo BASE.AMP.$changeUrl.'&campaignId=';?>'+this.options[this.selectedIndex].value;">
                        <?php foreach ($campaigns as $campaign):?>
                                <option value="<?php echo $campaign['campaign_id'];?>" <?php if ($campaign['campaign_id']==$currentcampaignId){echo 'selected="selected"';}?> ><?php echo $campaign['campaign_name'];?></option>
                        <?php endforeach;?>
                </select>
            </div>
        </div>
    </div>
    <div id="templateGroups">
        <div class="column">
            <div class="linkBar">
                <p class="go_notice"><?php echo $sucessMsg;?></p>
            </div>
            <div class="formHeading">
                <span>Apis</span>
            </div>
            <div class="groupList">
                <h3>Choose Api</h3>
                <ul id="sortable_template_groups" class="ui-sortable">
                    <?php foreach ($selectedApis as $api):?>
                            <li <?php if($api==$currentApi):?>class="selected"<?php endif;?>>
                                <a href="<?php echo BASE.AMP.'C=addons_modules'.AMP.'M=show_module_cp'
                                            .AMP.'module=spider'.AMP.'method=configFieldGroup&api='.$api.AMP.'campaignId='.$currentcampaignId;?>"
                                            class="<?php echo $api;?> templateGroupName" >
                                            <?php echo $apiNames[$api];?>
                                </a>
                            </li>
                    <?php endforeach;?>
                </ul>
            </div>
        </div>
    </div>
    <div id="templates">
        <div class="column">
            
            <div class="linkBar">
                
            </div>
            <div class="templateGrouping" style="display: block;">
                <div class="formHeading">
                    <span>Configure <?php echo $apiNames[$currentApi];?></span>
                </div>
                <table cellspacing="0" cellpadding="0" border="0" class="templateTable">
                    <thead>
                        <tr>
                            <th>Select</th>
                            <th>Options</th>
                            <th>Field Group</th>
                        </tr>
                    </thead>
                    <tbody>
                        <?php foreach ($fieldOptions as $fieldOption):?>
                        <?php foreach ($fieldOption as $key=>$value):?>
                        <?php if (substr($key, 0, strpos($key, '_'))!='fmt'): ?>
                        <tr>
                            <td><?php echo form_checkbox($key, $key, $value['attribute']['checked']);?></td>
                            <td><?php echo form_label($value['label'], $key);?></td>
                            <td>
                                <?php $fieldId=isset($value['fieldId'])?$value['fieldId']:0;?>
                                <select name="fieldGroup_<?php echo $key;?>">
                                <?php foreach ($fieldGroup as $fieldGroups):?>
                                        <option value="<?php echo $fieldGroups['field_id'];?>" <?php if ($fieldGroups['field_id']==$fieldId):?>selected="selected" <?php endif;?>><?php echo $fieldGroups['field_name'];?></option>
                                <?php endforeach;?>
                                </select>
                            </td>
                        </tr>
                        <?php endif; ?>
                        <?php endforeach;?>
                        <?php endforeach;?>
                    </tbody>
                </table>
                <p style="float:right"><?php echo form_submit(array('name'=>'optionSave', 'value'=>'Save', 'class' => 'submit'));?></p>
            </div>
        </div>
    </div>
    <div class="clear_left">&nbsp;</div>
</div>
<?php echo form_close();?>